//
//  WebSiteMapView.m
//  SUZHOUBANK
//
//  Created by saberLily on 16/4/11.
//  Copyright © 2016年 RuiFeng-WGCC. All rights reserved.
//

#import "WebSiteMapView.h"
#import <MapKit/MapKit.h>
@interface WebSiteMapView()<CLLocationManagerDelegate,MKMapViewDelegate>
@property (nonatomic,strong) MKMapView *mapView; /**< 地图 */
@property (nonatomic,strong) UILabel *title; /**< 江苏省 */
@property (nonatomic,strong) CLLocationManager *locationManager; /**< 定位管理 */
@end
@implementation WebSiteMapView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initializeDataSource];
        [self initializeUserInterface];

    }
    return self;
}
#pragma mark - initializeDataSource 初始化数据源
-(void)initializeDataSource{
    
    _locationManager = [[CLLocationManager alloc] init];
    [_locationManager requestAlwaysAuthorization];
    [_locationManager startUpdatingLocation];
    _locationManager.delegate = self;
}

#pragma mark - initializeUserInterface 初始化用户界面
-(void)initializeUserInterface{
    [self addSubview:self.title];
    [self addSubview:self.mapView];
}
#pragma mark *** MKMapViewDelegate ***
-(void)mapViewDidFailLoadingMap:(MKMapView *)mapView withError:(NSError *)error{
     NSLog(@"地图加载失败");
}

#pragma mark *** CLLocationManagerDelegate ***
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
    //定位失败
     NSLog(@"%@",error.localizedDescription);
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
    CLLocation *location = locations.lastObject;
    
    CLLocationDegrees weidu = location.coordinate.latitude;
    CLLocationDegrees jingdu = location.coordinate.longitude;
    CLLocationDegrees haiba = location.altitude;
    NSLog(@"经度：%.2f 纬度：%2f 海拔高度：%2f",weidu,jingdu,haiba);
    //停止定位
    [_locationManager stopUpdatingLocation];
}
#pragma mark *** getters ***
-(UILabel *)title{
    if (!_title) {
        _title = [[UILabel alloc] initWithFrame:CGRectMake(20, 15, 400, 40)];
        _title.font = [UIFont systemFontOfSize:23];
        _title.text = @"江苏省";
        _title.textAlignment = 0;
    }
    return _title;
}
-(MKMapView *)mapView{
    if (!_mapView) {
        _mapView = [[MKMapView alloc] initWithFrame:CGRectMake(20, 60, 800,700)];
        _mapView.mapType = MKMapTypeStandard;
        
        _mapView.userLocation.title = @"Elpsycongroo";
        _mapView.userLocation.subtitle = @"命运石之门";
        
        _mapView.showsScale = YES;
        _mapView.showsCompass = YES;
        _mapView.showsTraffic = YES;
        _mapView.delegate = self;
        
    }
    return _mapView;
}

@end
